﻿using Microsoft.Build.Utilities;
using MsBuildAccess.Common;
using Microsoft.Build.Framework;

namespace MsBuildAccess.Utility
{
    /// <summary>
    /// Access utility task
    /// </summary>
    public class AccessUtility : Task
    {
        [Required]
        public string SourceFile { get; set; }

        [Required]
        public string DestinationFile { get; set; }

        [Required]        
        public string TaskType { get; set; }

        public override bool Execute()
        {
            bool ret = true;
            //todo validate
            var logger = new Helper.Logger("normal",Log);
            var file = new MsAccessFile(null,AccessType.mdb,null,logger);
            switch (TaskType.ToLower())
            {
                case "compactrepair":
                    logger.LogMsg(string.Format("Compactmdb {0} {1}", SourceFile, DestinationFile));
                    ret = file.CompactRepair(this.SourceFile, this.DestinationFile);
                    break;
                case "makemde":                    
                    ret = file.MakeMde(this.SourceFile, this.DestinationFile);
                    break;
                //todo convert access file
                case "convert":
                    //ret = file.ConvertAccess(this.SourceFile, this.DestinationFile,AcFileFormat);
                    break;

            }
            return ret;
        }
    }
}
